///*
// * Copyright 2006-2022 ahtelit.com, All Rights Reserved.
// */
//
//package com.telit.firecommand.service.impl;
//
//import cn.hutool.core.collection.CollectionUtil;
//import cn.hutool.core.convert.Convert;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
//import com.baomidou.mybatisplus.core.metadata.IPage;
//import com.baomidou.mybatisplus.core.toolkit.Wrappers;
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
//import com.telit.common.core.utils.FeignUtils;
//import com.telit.common.dto.DistrictDTO;
//import com.telit.common.entity.PageData;
//import com.telit.common.enums.ResultCode;
//import com.telit.common.exception.ForestBaseException;
//import com.telit.common.util.DateUtils;
//import com.telit.common.util.LanguageUtils;
//import com.telit.firecommand.dao.AttendInfoDAO;
//import com.telit.firecommand.dao.AttendNoteInfoDAO;
//import com.telit.firecommand.dao.AttendRecordDAO;
//import com.telit.firecommand.dao.GeoXzqhCunDao;
//import com.telit.firecommand.dto.*;
//import com.telit.firecommand.entity.AttendInfo;
//import com.telit.firecommand.entity.AttendNoteInfo;
//import com.telit.firecommand.entity.AttendRecord;
//import com.telit.firecommand.model.attendInfo.SaveAttendInfoRequest;
//import com.telit.firecommand.model.attendInfo.SaveNoteRequest;
//import com.telit.firecommand.model.attendInfo.SignInRequest;
//import com.telit.firecommand.service.AttendInfoService;
//import com.telit.firecommand.service.DistrictService;
//import com.telit.upms.feign.RemoteUpmsService;
//import com.telit.upms.vo.MicroSysDistrictVo;
//import com.telit.upms.vo.MicroSysUserAllInfoVo;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.BeanUtils;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//
//import java.util.*;
//import java.util.stream.Collectors;
//
//
///**
// * AttendInfoServiceImpl
// *
// * @author yuezhuang
// * @since 2023-02-17
// */
//@RequiredArgsConstructor
//@Slf4j
//@Service
//@Transactional
//public class AttendInfoServiceImpl implements AttendInfoService {
//
//    private final RemoteUpmsService remoteUpmsService;
//
//    private final AttendInfoDAO attendInfoDAO;
//
//    private final AttendRecordDAO attendRecordDAO;
//
//    private final AttendNoteInfoDAO attendNoteInfoDAO;
//
//    private final GeoXzqhCunDao geoXzqhCunDao;
//
//    private final DistrictService districtService;
//
//
//    /**
//     * 保存值班信息
//     * 早班时间：09:00 - 18:00，晚班时间：当日 18:00 - 次日 09:00
//     *
//     * @param saveAttendInfoRequest SaveAttendInfoRequest
//     */
//    @Override
//    public void save(SaveAttendInfoRequest saveAttendInfoRequest) {
//        Long userId = saveAttendInfoRequest.getUserId();
//
//        String districtCode = saveAttendInfoRequest.getDistrictCode();
//        com.telit.common.core.utils.Result<Map<String, MicroSysDistrictVo>> selectDistrictDetailByListCodesResult = remoteUpmsService.selectDistrictDetailByListCodes(
//                Collections.singletonList(districtCode));
//        Map<String, MicroSysDistrictVo> microSysDistrictVoMap = FeignUtils.unwrap(
//                selectDistrictDetailByListCodesResult);
//        MicroSysDistrictVo microSysDistrictVo = microSysDistrictVoMap.get(districtCode);
//        if (microSysDistrictVo == null) {
//            throw new ForestBaseException(LanguageUtils.codeMessage(ResultCode.OPERATE_ERROR.getCode()));
//        }
//
//        List<SaveAttendInfoRequest.AttendInfoUser> userList = saveAttendInfoRequest.getUserList();
//        List<Long> ids = userList.stream().map(SaveAttendInfoRequest.AttendInfoUser::getUserId).collect(
//                Collectors.toList());
//        com.telit.common.core.utils.Result<Map<Long, MicroSysUserAllInfoVo>> selectUserContainDeptAndRoleWithBatchIdsResult = remoteUpmsService.selectUserContainDeptAndRoleWithBatchIds(
//                ids, true);
//        Map<Long, MicroSysUserAllInfoVo> longMicroSysUserAllInfoVoMap = FeignUtils.unwrap(
//                selectUserContainDeptAndRoleWithBatchIdsResult);
//
//        //删除当日该行政区划的其他排班信息
//        Date day = DateUtils.getDate(userList.get(0).getDay(), DateUtils.DATE_FORMAT);
//        LambdaUpdateWrapper<AttendInfo> attendInfoLambdaUpdateWrapper = Wrappers.lambdaUpdate();
//        attendInfoLambdaUpdateWrapper.set(AttendInfo::isDeleted, true);
//        attendInfoLambdaUpdateWrapper.eq(AttendInfo::getDistrictCode, districtCode);
//        attendInfoLambdaUpdateWrapper.eq(AttendInfo::getDay, day);
//        attendInfoDAO.update(null, attendInfoLambdaUpdateWrapper);
//
//        //重新添加
//        Date now = new Date();
//        List<AttendInfo> attendInfos = new ArrayList<>();
//        userList.forEach(attendInfoUser -> {
//            MicroSysUserAllInfoVo microSysUserAllInfoVo = longMicroSysUserAllInfoVoMap.get(attendInfoUser.getUserId());
//            if (microSysUserAllInfoVo != null) {
//                Date startTime = null;
//                Date endTime = null;
//                if (attendInfoUser.getTimeType() == 1) {
//                    startTime = DateUtils.addHour(day, 9);
//                    endTime = DateUtils.addHour(day, 18);
//                } else if (attendInfoUser.getTimeType() == 2) {
//                    startTime = DateUtils.addHour(day, 18);
//                    endTime = DateUtils.addHour(day, 33);
//                }
//                attendInfos.add(AttendInfo.builder()
//                        .userId(microSysUserAllInfoVo.getId())
//                        .districtCode(districtCode)
//                        .districtName(microSysDistrictVo.getName())
//                        .userName(microSysUserAllInfoVo.getUserName())
//                        .mobile(microSysUserAllInfoVo.getMobile())
//                        .deptId(microSysUserAllInfoVo.getDeptId())
//                        .deptName(microSysUserAllInfoVo.getDeptName())
//                        .duty(microSysUserAllInfoVo.getDuty())
//                        .day(day)
//                        .timeType(attendInfoUser.getTimeType())
//                        .startTime(startTime)
//                        .endTime(endTime)
//                        .createdAt(now)
//                        .createdBy(userId)
//                        .updatedAt(now)
//                        .updatedBy(userId)
//                        .deleted(false)
//                        .build());
//            }
//        });
//        if (CollectionUtil.isNotEmpty(attendInfos)) {
//            attendInfoDAO.insertBatchSomeColumn(attendInfos);
//        }
//    }
//
//    /**
//     * @param page         当前页，分页当前页
//     * @param limit        分页条数
//     * @param noPage       是否不分页，true-不分页
//     * @param districtCode 行政区划编码
//     * @param day          排班日期
//     * @param timeType     时间类型
//     *
//     * @return AttendInfoDTO
//     */
//    @Override
//    public PageData<List<AttendInfoDTO>> qryAttendInfoList(Integer page, Integer limit, boolean noPage,
//                                                           String districtCode, Date day, Integer timeType) {
//        if (noPage) {
//            limit = Integer.MAX_VALUE;
//        }
//        LambdaQueryWrapper<AttendInfo> queryWrapper = new LambdaQueryWrapper<>();
//        queryWrapper.eq(AttendInfo::getDistrictCode, districtCode);
//        queryWrapper.eq(AttendInfo::isDeleted, false);
//        if (day != null) {
//            queryWrapper.eq(AttendInfo::getDay, day);
//        }
//        if (timeType != null) {
//            queryWrapper.eq(AttendInfo::getTimeType, timeType);
//        }
//        IPage<AttendInfo> iPage = attendInfoDAO.selectPage(new Page<>(page, limit), queryWrapper);
//        int count = (int) iPage.getTotal();
//        if (count <= 0) {
//            return PageData.<List<AttendInfoDTO>>builder().count(0).current(page).size(limit).datas(
//                    new ArrayList<>()).build();
//        }
//        List<AttendInfo> attendInfos = iPage.getRecords();
//        List<AttendInfoDTO> attendInfoDTOS = attendInfos.stream().map(
//                attendInfo -> Convert.convert(AttendInfoDTO.class, attendInfo)).collect(Collectors.toList());
//
//        return PageData.<List<AttendInfoDTO>>builder().count(count).current(page).size(limit).datas(
//                attendInfoDTOS).build();
//    }
//
//    /**
//     * 根据行政区划编码查询排班列表
//     *
//     * @param page         当前页，分页当前页
//     * @param limit        分页条数
//     * @param noPage       是否不分页，true-不分页
//     * @param districtCode 行政区划编码
//     * @param rank         行政区划层级, 1-省 2-市 3-区县 4-乡镇 5-村（不传默认为当前一级）
//     * @param day          排班日期
//     *
//     * @return AttendDTO
//     */
//    @Override
//    public PageData<List<AttendDTO>> qryAttendList(Integer page, Integer limit, boolean noPage, String districtCode,
//                                                   Integer rank, Date day) {
//        PageData<List<DistrictDTO>> listPageData = districtService.qryListByParentCodeWithPage(districtCode, rank, true,
//                page, limit, noPage);
//        List<DistrictDTO> districtList = listPageData.getDatas();
//
//        List<AttendDTO> attendDTOS = new ArrayList<>();
//        districtList.forEach(districtDTO -> {
//            PageData<List<AttendInfoDTO>> morningList = qryAttendInfoList(1, Integer.MAX_VALUE, true,
//                    districtDTO.getCode(), day,
//                    1);
//            PageData<List<AttendInfoDTO>> nightList = qryAttendInfoList(1, Integer.MAX_VALUE, true,
//                    districtDTO.getCode(), day,
//                    2);
//            attendDTOS.add(AttendDTO.builder()
//                    .districtCode(districtDTO.getCode())
//                    .districtName(districtDTO.getName())
//                    .morningList(morningList)
//                    .nightList(nightList)
//                    .build());
//        });
//        return PageData.<List<AttendDTO>>builder()
//                .count(listPageData.getCount())
//                .current(page)
//                .size(limit)
//                .datas(attendDTOS)
//                .build();
//    }
//
//    /**
//     * 签到/签退
//     *
//     * @param signInRequest signInRequest
//     */
//    @Override
//    public void signIn(SignInRequest signInRequest) {
//        Long userId = signInRequest.getUserId();
//        String districtCode = signInRequest.getDistrictCode();
//
//        com.telit.common.core.utils.Result<Map<Long, MicroSysUserAllInfoVo>> selectUserContainDeptAndRoleWithBatchIdsResult = remoteUpmsService.selectUserContainDeptAndRoleWithBatchIds(
//                Arrays.asList(userId), true);
//        Map<Long, MicroSysUserAllInfoVo> longMicroSysUserAllInfoVoMap = FeignUtils.unwrap(
//                selectUserContainDeptAndRoleWithBatchIdsResult);
//        MicroSysUserAllInfoVo microSysUserAllInfoVo = longMicroSysUserAllInfoVoMap.get(userId);
//        if (microSysUserAllInfoVo == null) {
//            throw new ForestBaseException(LanguageUtils.codeMessage(ResultCode.OPERATE_ERROR.getCode(), userId));
//        }
//
//        LambdaQueryWrapper<AttendInfo> attendInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::isDeleted, false);
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::getId, signInRequest.getAttendInfoId());
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::getUserId, userId);
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::getDistrictCode, districtCode);
//        AttendInfo attendInfo = attendInfoDAO.selectOne(attendInfoLambdaQueryWrapper);
//        if (attendInfo == null) {
//            throw new ForestBaseException(
//                    LanguageUtils.codeMessage(ResultCode.OPERATE_ERROR.getCode(), signInRequest.getAttendInfoId()));
//        }
//
//        LambdaQueryWrapper<AttendRecord> attendRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        attendRecordLambdaQueryWrapper.eq(AttendRecord::isDeleted, false);
//        attendRecordLambdaQueryWrapper.eq(AttendRecord::getUserId, userId);
//        attendRecordLambdaQueryWrapper.eq(AttendRecord::getDistrictCode, districtCode);
//        attendRecordLambdaQueryWrapper.eq(AttendRecord::getAttendId, signInRequest.getAttendInfoId());
//        if (1 == signInRequest.getAction()) {//签到
//            attendRecordLambdaQueryWrapper.isNotNull(AttendRecord::getStartType);
//        } else {
//            attendRecordLambdaQueryWrapper.isNotNull(AttendRecord::getEndType);
//        }
//        AttendRecord attendRecord = attendRecordDAO.selectOne(attendRecordLambdaQueryWrapper);
//        if (attendRecord != null) {
//            throw new ForestBaseException(
//                    LanguageUtils.codeMessage(ResultCode.RECORD_EXIST.getCode(), signInRequest.getAttendInfoId()));
//        }
//
//        Date now = new Date();
//        attendRecord = AttendRecord.builder()
//                .userId(microSysUserAllInfoVo.getId())
//                .districtCode(districtCode)
//                .districtName(attendInfo.getDistrictName())
//                .userName(microSysUserAllInfoVo.getUserName())
//                .mobile(microSysUserAllInfoVo.getMobile())
//                .deptId(microSysUserAllInfoVo.getDeptId())
//                .deptName(microSysUserAllInfoVo.getDeptName())
//                .duty(microSysUserAllInfoVo.getDuty())
//                .day(attendInfo.getDay())
//                .timeType(attendInfo.getTimeType())
//                .startTime(attendInfo.getStartTime())
//                .endTime(attendInfo.getEndTime())
//                .createdAt(now)
//                .createdBy(userId)
//                .updatedAt(now)
//                .updatedBy(userId)
//                .deleted(false)
//                .attendId(signInRequest.getAttendInfoId())
//                .submitAt(now)
//                .build();
//        if (1 == signInRequest.getAction()) {//签到
//            Date startTime = attendInfo.getStartTime();
//            attendRecord.setStartType(2);
//            if (startTime.after(now)) {
//                attendRecord.setStartType(1);
//            }
//        } else {
//            Date endTime = attendInfo.getEndTime();
//            attendRecord.setEndType(2);
//            if (endTime.before(now)) {
//                attendRecord.setEndType(1);
//            }
//        }
//        attendRecordDAO.insert(attendRecord);
//    }
//
//    /**
//     * 查询下次班次日期
//     *
//     * @param userId       用户id
//     * @param districtCode 行政区划编码
//     * @param day          当前日期
//     *
//     * @return AttendInfoDTO
//     */
//    @Override
//    public AttendInfoDTO qryNextAttend(Long userId, String districtCode, Date day) {
//        LambdaQueryWrapper<AttendInfo> attendInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::isDeleted, false);
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::getUserId, userId);
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::getDistrictCode, districtCode);
//        attendInfoLambdaQueryWrapper.gt(AttendInfo::getDay, day);
//        attendInfoLambdaQueryWrapper.orderByAsc(true, AttendInfo::getDay, AttendInfo::getTimeType);
//        attendInfoLambdaQueryWrapper.last("limit 1");
//        AttendInfo attendInfo = attendInfoDAO.selectOne(attendInfoLambdaQueryWrapper);
//        if (attendInfo == null) {
//            return null;
//        }
//
//        AttendInfoDTO attendInfoDTO = new AttendInfoDTO();
//        BeanUtils.copyProperties(attendInfo, attendInfoDTO);
//        return attendInfoDTO;
//    }
//
//    /**
//     * 保存晨报、值班信息、交班信息、应急事务
//     *
//     * @param saveNoteRequest saveNoteRequest
//     */
//    @Override
//    public void saveNote(SaveNoteRequest saveNoteRequest) {
//        if (saveNoteRequest.getEmergencyAffairs() != null) {
//            saveEmergencyAffairs(saveNoteRequest);
//        } else if (saveNoteRequest.getDaily() != null) {
//            saveDaily(saveNoteRequest);
//        } else if (saveNoteRequest.getDuty() != null) {
//            saveDuty(saveNoteRequest);
//        } else if (saveNoteRequest.getTurn() != null) {
//            saveTurn(saveNoteRequest);
//        }
//    }
//
//    /**
//     * 分页查询应急事务
//     *
//     * @param page         当前页，分页当前页
//     * @param limit        分页条数
//     * @param noPage       是否不分页，true-不分页
//     * @param userId       用户id
//     * @param districtCode 行政区划编码
//     * @param attendInfoId 班次id
//     *
//     * @return EmergencyAffairsDTO
//     */
//    @Override
//    public PageData<List<EmergencyAffairsDTO>> qryEmergency(Integer page, Integer limit, boolean noPage, Long userId,
//                                                            String districtCode, Long attendInfoId) {
//        if (noPage) {
//            limit = Integer.MAX_VALUE;
//        }
//        LambdaQueryWrapper<AttendNoteInfo> queryWrapper = new LambdaQueryWrapper<>();
//        queryWrapper.eq(AttendNoteInfo::isDeleted, false);
//        queryWrapper.eq(AttendNoteInfo::getUserId, userId);
//        queryWrapper.eq(AttendNoteInfo::getDistrictCode, districtCode);
//        queryWrapper.eq(AttendNoteInfo::getAttendId, attendInfoId);
//        queryWrapper.eq(AttendNoteInfo::getType, 4);
//        IPage<AttendNoteInfo> iPage = attendNoteInfoDAO.selectPage(new Page<>(page, limit), queryWrapper);
//        int count = (int) iPage.getTotal();
//        if (count <= 0) {
//            return PageData.<List<EmergencyAffairsDTO>>builder().count(0).current(page).size(limit).datas(
//                    new ArrayList<>()).build();
//        }
//
//        List<AttendNoteInfo> attendNoteInfos = iPage.getRecords();
//        List<EmergencyAffairsDTO> emergencyAffairsDTOS = attendNoteInfos.stream().map(
//                attendNoteInfo -> Convert.convert(EmergencyAffairsDTO.class, attendNoteInfo)).collect(
//                Collectors.toList());
//        emergencyAffairsDTOS = emergencyAffairsDTOS.stream().peek(emergencyAffairsDTO -> {
//            //领导指示
//            LambdaQueryWrapper<AttendNoteInfo> attendNoteInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
//            attendNoteInfoLambdaQueryWrapper.eq(AttendNoteInfo::isDeleted, false);
//            attendNoteInfoLambdaQueryWrapper.eq(AttendNoteInfo::getUserId, userId);
//            attendNoteInfoLambdaQueryWrapper.eq(AttendNoteInfo::getDistrictCode, districtCode);
//            attendNoteInfoLambdaQueryWrapper.eq(AttendNoteInfo::getAttendId, attendInfoId);
//            attendNoteInfoLambdaQueryWrapper.eq(AttendNoteInfo::getParentId, emergencyAffairsDTO.getId());
//            attendNoteInfoLambdaQueryWrapper.eq(AttendNoteInfo::getType, 5);
//            List<AttendNoteInfo> leaderInstructDTOS = attendNoteInfoDAO.selectList(attendNoteInfoLambdaQueryWrapper);
//            emergencyAffairsDTO.setLeaderInstructDTOS(leaderInstructDTOS.stream().map(
//                    attendNoteInfo -> Convert.convert(LeaderInstructDTO.class, attendNoteInfo)).collect(
//                    Collectors.toList()));
//        }).collect(Collectors.toList());
//
//        return PageData.<List<EmergencyAffairsDTO>>builder().count(count).current(page).size(limit).datas(
//                emergencyAffairsDTOS).build();
//    }
//
//    /**
//     * 查询交班信息
//     *
//     * @param userId       用户id
//     * @param districtCode 行政区划编码
//     * @param attendInfoId 班次id
//     *
//     * @return TurnDTO
//     */
//    @Override
//    public List<TurnDTO> qryTurn(Long userId, String districtCode, Long attendInfoId) {
//        LambdaQueryWrapper<AttendNoteInfo> attendNoteInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        attendNoteInfoLambdaQueryWrapper.eq(AttendNoteInfo::isDeleted, false);
//        attendNoteInfoLambdaQueryWrapper.eq(AttendNoteInfo::getUserId, userId);
//        attendNoteInfoLambdaQueryWrapper.eq(AttendNoteInfo::getDistrictCode, districtCode);
//        attendNoteInfoLambdaQueryWrapper.eq(AttendNoteInfo::getAttendId, attendInfoId);
//        attendNoteInfoLambdaQueryWrapper.eq(AttendNoteInfo::getType, 3);
//        List<AttendNoteInfo> attendNoteInfos = attendNoteInfoDAO.selectList(attendNoteInfoLambdaQueryWrapper);
//        return attendNoteInfos.stream().map(attendNoteInfo -> Convert.convert(TurnDTO.class, attendNoteInfo)).collect(
//                Collectors.toList());
//    }
//
//    /**
//     * 查询值班记录
//     *
//     * @param userId       用户id
//     * @param districtCode 行政区划编码
//     * @param attendInfoId 班次id
//     *
//     * @return TurnDTO
//     */
//    @Override
//    public List<DutyDTO> qryDuty(Long userId, String districtCode, Long attendInfoId) {
//        LambdaQueryWrapper<AttendNoteInfo> attendNoteInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        attendNoteInfoLambdaQueryWrapper.eq(AttendNoteInfo::isDeleted, false);
//        attendNoteInfoLambdaQueryWrapper.eq(AttendNoteInfo::getUserId, userId);
//        attendNoteInfoLambdaQueryWrapper.eq(AttendNoteInfo::getDistrictCode, districtCode);
//        attendNoteInfoLambdaQueryWrapper.eq(AttendNoteInfo::getAttendId, attendInfoId);
//        attendNoteInfoLambdaQueryWrapper.eq(AttendNoteInfo::getType, 2);
//        List<AttendNoteInfo> attendNoteInfos = attendNoteInfoDAO.selectList(attendNoteInfoLambdaQueryWrapper);
//        return attendNoteInfos.stream().map(attendNoteInfo -> Convert.convert(DutyDTO.class, attendNoteInfo)).collect(
//                Collectors.toList());
//    }
//
//    /**
//     * 查询日报
//     *
//     * @param userId       用户id
//     * @param districtCode 行政区划编码
//     * @param attendInfoId 班次id
//     *
//     * @return DailyDTO
//     */
//    @Override
//    public List<DailyDTO> qryDaily(Long userId, String districtCode, Long attendInfoId) {
//        LambdaQueryWrapper<AttendNoteInfo> attendNoteInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        attendNoteInfoLambdaQueryWrapper.eq(AttendNoteInfo::isDeleted, false);
//        attendNoteInfoLambdaQueryWrapper.eq(AttendNoteInfo::getUserId, userId);
//        attendNoteInfoLambdaQueryWrapper.eq(AttendNoteInfo::getDistrictCode, districtCode);
//        attendNoteInfoLambdaQueryWrapper.eq(AttendNoteInfo::getAttendId, attendInfoId);
//        attendNoteInfoLambdaQueryWrapper.eq(AttendNoteInfo::getType, 1);
//        List<AttendNoteInfo> attendNoteInfos = attendNoteInfoDAO.selectList(attendNoteInfoLambdaQueryWrapper);
//        return attendNoteInfos.stream().map(attendNoteInfo -> Convert.convert(DailyDTO.class, attendNoteInfo)).collect(
//                Collectors.toList());
//    }
//
//    /**
//     * 查询交班人列表
//     *
//     * @param userId       用户id
//     * @param districtCode 行政区划编码
//     * @param attendInfoId 班次id
//     *
//     * @return AttendInfoDTO
//     */
//    @Override
//    public List<AttendInfoDTO> qryNextUser(Long userId, String districtCode, Long attendInfoId) {
//        LambdaQueryWrapper<AttendInfo> attendInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::isDeleted, false);
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::getId, attendInfoId);
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::getUserId, userId);
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::getDistrictCode, districtCode);
//        AttendInfo attendInfo = attendInfoDAO.selectOne(attendInfoLambdaQueryWrapper);
//        if (attendInfo == null) {
//            throw new ForestBaseException(
//                    LanguageUtils.codeMessage(ResultCode.OPERATE_ERROR.getCode(), attendInfoId));
//        }
//
//        //下一个班次：如果是早班，则查询当天的晚班 或者 下一个日期的班次
//        //下一个班次：如果是晚班，则查询下一个日期的班次
//        if (attendInfo.getTimeType() == 1) {//早班
//            LambdaQueryWrapper<AttendInfo> infoLambdaQueryWrapper = new LambdaQueryWrapper<>();
//            infoLambdaQueryWrapper.eq(AttendInfo::isDeleted, false);
//            infoLambdaQueryWrapper.eq(AttendInfo::getDistrictCode, districtCode);
//            infoLambdaQueryWrapper.eq(AttendInfo::getDay, attendInfo.getDay());
//            infoLambdaQueryWrapper.eq(AttendInfo::getTimeType, 2);
//            List<AttendInfo> nextAttendList = attendInfoDAO.selectList(infoLambdaQueryWrapper);
//            if (CollectionUtil.isNotEmpty(nextAttendList)) {
//                return nextAttendList.stream().map(attend -> Convert.convert(AttendInfoDTO.class, attend)).collect(
//                        Collectors.toList());
//            }
//        }
//
//        //下一个日期的班次
//        LambdaQueryWrapper<AttendInfo> infoLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        infoLambdaQueryWrapper.eq(AttendInfo::isDeleted, false);
//        infoLambdaQueryWrapper.eq(AttendInfo::getDistrictCode, districtCode);
//        infoLambdaQueryWrapper.gt(AttendInfo::getDay, attendInfo.getDay());
//        infoLambdaQueryWrapper.orderByAsc(true, AttendInfo::getDay, AttendInfo::getTimeType);
//        infoLambdaQueryWrapper.last("limit 1");
//        AttendInfo nextDateAttend = attendInfoDAO.selectOne(infoLambdaQueryWrapper);
//        if (nextDateAttend == null) {
//            return null;
//        }
//
//        //查询人员
//        LambdaQueryWrapper<AttendInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
//        lambdaQueryWrapper.eq(AttendInfo::isDeleted, false);
//        lambdaQueryWrapper.eq(AttendInfo::getDistrictCode, districtCode);
//        lambdaQueryWrapper.eq(AttendInfo::getDay, nextDateAttend.getDay());
//        lambdaQueryWrapper.eq(AttendInfo::getTimeType, nextDateAttend.getTimeType());
//        List<AttendInfo> nextAttendList = attendInfoDAO.selectList(lambdaQueryWrapper);
//        return nextAttendList.stream().map(attend -> Convert.convert(AttendInfoDTO.class, attend)).collect(
//                Collectors.toList());
//    }
//
//    /**
//     * 查询当前班次详情
//     *
//     * @param userId       用户id
//     * @param districtCode 行政区划编码
//     *
//     * @return CurrentAttendInfoDTO
//     */
//    @Override
//    public CurrentAttendInfoDTO qryCurrentInfo(Long userId, String districtCode, Date day) {
//        if (day == null) {
//            day = new Date();
//        }
//        AttendInfoDTO attendInfo = qryCurrentAttend(userId, districtCode, day);
//        AttendInfoDTO nextAttendInfo = qryNextAttend(userId, districtCode,
//                DateUtils.getDate(DateUtils.parse(day, DateUtils.DATE_FORMAT), DateUtils.DATE_FORMAT));
//
//        boolean signIn = false;
//        boolean signOut = false;
//        boolean daily = false;
//        boolean duty = false;
//        boolean turn = false;
//        if (attendInfo != null) {
//            List<AttendRecordDTO> attendRecordDTOS = qrySignIn(userId, districtCode, attendInfo.getId());
//            long count = attendRecordDTOS.stream().filter(
//                    attendRecordDTO -> attendRecordDTO.getStartType() != null).count();
//
//            long count2 = attendRecordDTOS.stream().filter(
//                    attendRecordDTO -> attendRecordDTO.getEndType() != null).count();
//            signIn = count > 0;
//            signOut = count2 > 0;
//
//            List<DailyDTO> dailyDTOS = qryDaily(userId, districtCode, attendInfo.getId());
//            daily = CollectionUtil.isNotEmpty(dailyDTOS);
//
//            List<DutyDTO> dutyDTOS = qryDuty(userId, districtCode, attendInfo.getId());
//            duty = CollectionUtil.isNotEmpty(dutyDTOS);
//
//            List<TurnDTO> turnDTOS = qryTurn(userId, districtCode, attendInfo.getId());
//            turn = CollectionUtil.isNotEmpty(turnDTOS);
//        }
//
//        return CurrentAttendInfoDTO.builder()
//                .attendInfo(attendInfo)
//                .nextAttendInfo(nextAttendInfo)
//                .signIn(signIn)
//                .signOut(signOut)
//                .daily(daily)
//                .duty(duty)
//                .turn(turn)
//                .build();
//    }
//
//    /**
//     * 查询到岗统计
//     *
//     * @param userId       用户id
//     * @param districtCode 行政区划编码
//     * @param day          查询日期，不传默认当天
//     *
//     * @return AttendStatisticsDTO
//     */
//    @Override
//    public AttendStatisticsDTO qryAttendStatistics(Long userId, String districtCode, Date day) {
//        //值班信息
//        LambdaQueryWrapper<AttendInfo> attendInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::isDeleted, false);
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::getDistrictCode, districtCode);
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::getDay, day);
//        List<AttendInfo> attendInfos = attendInfoDAO.selectList(attendInfoLambdaQueryWrapper);
//
//        //应到人数
//        Integer totalCount = attendInfos.size();
//
//        //实到人数
//        QueryWrapper<AttendRecord> attendRecordQueryWrapper = new QueryWrapper<>();
//        attendRecordQueryWrapper.eq("deleted", false);
//        attendRecordQueryWrapper.eq("district_code", districtCode);
//        attendRecordQueryWrapper.eq("day", day);
//        attendRecordQueryWrapper.select("DISTINCT attend_id");
//        Integer realCount = attendRecordDAO.selectCount(attendRecordQueryWrapper);
//        if (realCount == null) {
//            realCount = 0;
//        }
//
////        //到岗率
////        BigDecimal ratio = BigDecimal.ZERO;
////        if (totalCount != 0) {
////            ratio = (BigDecimal.valueOf(realCount).divide(BigDecimal.valueOf(totalCount))).setScale(2,
////                    BigDecimal.ROUND_HALF_UP);
////        }
//
//        return AttendStatisticsDTO.builder()
//                .totalCount(totalCount)
//                .realCount(realCount)
////                .ratio(ratio)
//                .attendList(attendInfos.stream().map(
//                        attendInfo -> Convert.convert(AttendInfoDTO.class, attendInfo)).collect(Collectors.toList()))
//                .build();
//    }
//
//    /**
//     * 删除 晨报、值班信息、交班信息、应急事务
//     *
//     * @param id id
//     */
//    @Override
//    public void delNote(Long id) {
//        LambdaUpdateWrapper<AttendNoteInfo> attendNoteInfoLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
//        attendNoteInfoLambdaUpdateWrapper.eq(AttendNoteInfo::getId, id);
//        attendNoteInfoLambdaUpdateWrapper.set(AttendNoteInfo::isDeleted, true);
//        attendNoteInfoDAO.update(null, attendNoteInfoLambdaUpdateWrapper);
//    }
//
//    /**
//     * 查询当前班次信息
//     *
//     * @param userId       用户id
//     * @param districtCode 行政区划编码
//     * @param day          查询日期，不传默认当天
//     *
//     * @return AttendInfoDTO
//     */
//    @Override
//    public AttendInfoDTO qryCurrentAttend(Long userId, String districtCode, Date day) {
//        //早班时间：09:00 - 18:00，晚班时间：当日 18:00 - 次日 09:00
//        //查询此刻的班次信息
//        //或者上一个班次是否未签退 并且 到签退时间两个小时内（延迟两个小时可以签退）
//
//        Date now = new Date();
//        if (day == null) {
//            day = now;
//        }
//
//        //前一天班次，只需要查询晚班次
//        Date lastDay = DateUtils.addDay(day, -1);
//        LambdaQueryWrapper<AttendInfo> lastDayWrapper = new LambdaQueryWrapper<>();
//        lastDayWrapper.eq(AttendInfo::isDeleted, false);
//        lastDayWrapper.eq(AttendInfo::getUserId, userId);
//        lastDayWrapper.eq(AttendInfo::getDistrictCode, districtCode);
//        lastDayWrapper.eq(AttendInfo::getDay,
//                DateUtils.getDate(DateUtils.parse(lastDay, DateUtils.DATE_FORMAT), DateUtils.DATE_FORMAT));
//        lastDayWrapper.eq(AttendInfo::getTimeType, 2);
//        lastDayWrapper.orderByAsc(true, AttendInfo::getDay, AttendInfo::getTimeType);
//        List<AttendInfo> lastDayAttendList = attendInfoDAO.selectList(lastDayWrapper);
//        if (CollectionUtil.isNotEmpty(lastDayAttendList)) {
//            //未签退，并且在两个小时之内
//            LambdaQueryWrapper<AttendRecord> lastDaySignOutLambdaQueryWrapper = new LambdaQueryWrapper<>();
//            lastDaySignOutLambdaQueryWrapper.eq(AttendRecord::isDeleted, false);
//            lastDaySignOutLambdaQueryWrapper.eq(AttendRecord::getUserId, userId);
//            lastDaySignOutLambdaQueryWrapper.eq(AttendRecord::getDistrictCode, districtCode);
//            lastDaySignOutLambdaQueryWrapper.eq(AttendRecord::getAttendId, lastDayAttendList.get(0).getId());
//            lastDaySignOutLambdaQueryWrapper.isNotNull(AttendRecord::getEndType);
//            AttendRecord signOut = attendRecordDAO.selectOne(lastDaySignOutLambdaQueryWrapper);
//            if (signOut == null) {
//                Date endTime = lastDayAttendList.get(0).getEndTime();
//                Date cutOffTime = DateUtils.addHour(endTime, 2);
//                if (now.compareTo(cutOffTime) < 0) {//结束后两个小时之内
//                    AttendInfoDTO attendInfoDTO = new AttendInfoDTO();
//                    BeanUtils.copyProperties(lastDayAttendList.get(0), attendInfoDTO);
//                    return attendInfoDTO;
//                }
//            }
//        }
//
//        //当天班次，包括早晚班
//        LambdaQueryWrapper<AttendInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
//        lambdaQueryWrapper.eq(AttendInfo::isDeleted, false);
//        lambdaQueryWrapper.eq(AttendInfo::getUserId, userId);
//        lambdaQueryWrapper.eq(AttendInfo::getDistrictCode, districtCode);
//        lambdaQueryWrapper.eq(AttendInfo::getDay,
//                DateUtils.getDate(DateUtils.parse(day, DateUtils.DATE_FORMAT), DateUtils.DATE_FORMAT));
//        lambdaQueryWrapper.orderByAsc(true, AttendInfo::getDay, AttendInfo::getTimeType);
//        List<AttendInfo> currentAttendList = attendInfoDAO.selectList(lambdaQueryWrapper);
//        if (CollectionUtil.isEmpty(currentAttendList)) {
//            return null;
//        }
//
//        //多个排班，判断是否没有签到或者签退
//        for (AttendInfo attendInfo : currentAttendList) {
//            //未签到
////            LambdaQueryWrapper<AttendRecord> signInLambdaQueryWrapper = new LambdaQueryWrapper<>();
////            signInLambdaQueryWrapper.eq(AttendRecord::isDeleted, false);
////            signInLambdaQueryWrapper.eq(AttendRecord::getUserId, userId);
////            signInLambdaQueryWrapper.eq(AttendRecord::getDistrictCode, districtCode);
////            signInLambdaQueryWrapper.eq(AttendRecord::getAttendId, attendInfo.getId());
////            signInLambdaQueryWrapper.isNotNull(AttendRecord::getStartType);
////            AttendRecord signIn = attendRecordDAO.selectOne(signInLambdaQueryWrapper);
////            if (signIn == null) {
////                AttendInfoDTO attendInfoDTO = new AttendInfoDTO();
////                BeanUtils.copyProperties(attendInfo, attendInfoDTO);
////                return attendInfoDTO;
////            }
//
//            //未签退
//            LambdaQueryWrapper<AttendRecord> signOutLambdaQueryWrapper = new LambdaQueryWrapper<>();
//            signOutLambdaQueryWrapper.eq(AttendRecord::isDeleted, false);
//            signOutLambdaQueryWrapper.eq(AttendRecord::getUserId, userId);
//            signOutLambdaQueryWrapper.eq(AttendRecord::getDistrictCode, districtCode);
//            signOutLambdaQueryWrapper.eq(AttendRecord::getAttendId, attendInfo.getId());
//            signOutLambdaQueryWrapper.isNotNull(AttendRecord::getEndType);
//            AttendRecord signOut = attendRecordDAO.selectOne(signOutLambdaQueryWrapper);
//            if (signOut == null) {
//                Date endTime = attendInfo.getEndTime();
//                Date cutOffTime = DateUtils.addHour(endTime, 2);
//                if (now.compareTo(cutOffTime) < 0) {//结束后两个小时之内
//                    AttendInfoDTO attendInfoDTO = new AttendInfoDTO();
//                    BeanUtils.copyProperties(attendInfo, attendInfoDTO);
//                    return attendInfoDTO;
//                }
//            }
//        }
//
//        AttendInfoDTO attendInfoDTO = new AttendInfoDTO();
//        BeanUtils.copyProperties(currentAttendList.get(0), attendInfoDTO);
//        return attendInfoDTO;
//    }
//
//    /**
//     * 查询班次签到信息
//     *
//     * @param userId       用户id
//     * @param districtCode 行政区划编码
//     * @param attendInfoId 班次id
//     *
//     * @return AttendRecordDTO
//     */
//    @Override
//    public List<AttendRecordDTO> qrySignIn(Long userId, String districtCode, Long attendInfoId) {
//        LambdaQueryWrapper<AttendRecord> attendRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        attendRecordLambdaQueryWrapper.eq(AttendRecord::isDeleted, false);
//        attendRecordLambdaQueryWrapper.eq(AttendRecord::getAttendId, attendInfoId);
//        attendRecordLambdaQueryWrapper.eq(AttendRecord::getUserId, userId);
//        attendRecordLambdaQueryWrapper.eq(AttendRecord::getDistrictCode, districtCode);
//        attendRecordLambdaQueryWrapper.orderByAsc(true, AttendRecord::getCreatedAt);
//        List<AttendRecord> attendRecords = attendRecordDAO.selectList(attendRecordLambdaQueryWrapper);
//        return attendRecords.stream().map(
//                attendRecord -> Convert.convert(AttendRecordDTO.class, attendRecord)).collect(Collectors.toList());
//    }
//
//    /**
//     * 保存应急信息
//     *
//     * @param saveNoteRequest saveNoteRequest
//     */
//    public void saveEmergencyAffairs(SaveNoteRequest saveNoteRequest) {
//        Long userId = saveNoteRequest.getUserId();
//        String districtCode = saveNoteRequest.getDistrictCode();
//
//        com.telit.common.core.utils.Result<Map<Long, MicroSysUserAllInfoVo>> selectUserContainDeptAndRoleWithBatchIdsResult = remoteUpmsService.selectUserContainDeptAndRoleWithBatchIds(
//                Collections.singletonList(userId), true);
//        Map<Long, MicroSysUserAllInfoVo> longMicroSysUserAllInfoVoMap = FeignUtils.unwrap(
//                selectUserContainDeptAndRoleWithBatchIdsResult);
//        MicroSysUserAllInfoVo microSysUserAllInfoVo = longMicroSysUserAllInfoVoMap.get(userId);
//        if (microSysUserAllInfoVo == null) {
//            throw new ForestBaseException(LanguageUtils.codeMessage(ResultCode.OPERATE_ERROR.getCode(), userId));
//        }
//
//        LambdaQueryWrapper<AttendInfo> attendInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::isDeleted, false);
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::getId, saveNoteRequest.getAttendInfoId());
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::getUserId, userId);
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::getDistrictCode, districtCode);
//        AttendInfo attendInfo = attendInfoDAO.selectOne(attendInfoLambdaQueryWrapper);
//        if (attendInfo == null) {
//            throw new ForestBaseException(
//                    LanguageUtils.codeMessage(ResultCode.OPERATE_ERROR.getCode(), saveNoteRequest.getAttendInfoId()));
//        }
//
//        SaveNoteRequest.EmergencyAffairs emergencyAffairs = saveNoteRequest.getEmergencyAffairs();
//        Long id = emergencyAffairs.getId();
//        Date now = new Date();
//        if (id == null) {
//            AttendNoteInfo attendNoteInfo = AttendNoteInfo.builder()
//                    .userId(microSysUserAllInfoVo.getId())
//                    .districtCode(districtCode)
//                    .districtName(attendInfo.getDistrictName())
//                    .userName(microSysUserAllInfoVo.getUserName())
//                    .mobile(microSysUserAllInfoVo.getMobile())
//                    .deptId(microSysUserAllInfoVo.getDeptId())
//                    .deptName(microSysUserAllInfoVo.getDeptName())
//                    .duty(microSysUserAllInfoVo.getDuty())
//                    .createdAt(now)
//                    .createdBy(userId)
//                    .updatedAt(now)
//                    .updatedBy(userId)
//                    .deleted(false)
//                    .attendId(saveNoteRequest.getAttendInfoId())
//                    .submitAt(now)
//                    .timeAt(DateUtils.parse(emergencyAffairs.getTimeAt(), DateUtils.yyyy_MM_dd_HH_mm_ss))
//                    .type(4)
//                    .eventType(emergencyAffairs.getEventType())
//                    .title(emergencyAffairs.getTitle())
//                    .place(emergencyAffairs.getPlace())
//                    .longitude(emergencyAffairs.getLongitude())
//                    .latitude(emergencyAffairs.getLatitude())
//                    .siteSituation(emergencyAffairs.getSiteSituation())
//                    .currentSituation(emergencyAffairs.getCurrentSituation())
//                    .disposal(emergencyAffairs.getDisposal())
//                    .description(emergencyAffairs.getDescription())
//                    .build();
//            attendNoteInfoDAO.insert(attendNoteInfo);
//
//            //领导指示
//            List<String> descriptionList = emergencyAffairs.getDescriptionList();
//            if (CollectionUtil.isNotEmpty(descriptionList)) {
//                List<AttendNoteInfo> attendNoteInfos = new ArrayList<>();
//                descriptionList.forEach(s -> {
//                    attendNoteInfos.add(AttendNoteInfo.builder()
//                            .userId(microSysUserAllInfoVo.getId())
//                            .districtCode(districtCode)
//                            .districtName(attendInfo.getDistrictName())
//                            .userName(microSysUserAllInfoVo.getUserName())
//                            .mobile(microSysUserAllInfoVo.getMobile())
//                            .deptId(microSysUserAllInfoVo.getDeptId())
//                            .deptName(microSysUserAllInfoVo.getDeptName())
//                            .duty(microSysUserAllInfoVo.getDuty())
//                            .createdAt(now)
//                            .createdBy(userId)
//                            .updatedAt(now)
//                            .updatedBy(userId)
//                            .deleted(false)
//                            .attendId(saveNoteRequest.getAttendInfoId())
//                            .submitAt(now)
//                            .type(5)
//                            .parentId(attendNoteInfo.getId())
//                            .description(s)
//                            .build());
//                });
//                attendNoteInfoDAO.insertBatchSomeColumn(attendNoteInfos);
//            }
//        } else {
//            //修改
//            LambdaQueryWrapper<AttendNoteInfo> attendNoteInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
//            attendNoteInfoLambdaQueryWrapper.eq(AttendNoteInfo::isDeleted, false);
//            attendNoteInfoLambdaQueryWrapper.eq(AttendNoteInfo::getId, id);
//            AttendNoteInfo attendNoteInfo = attendNoteInfoDAO.selectOne(attendNoteInfoLambdaQueryWrapper);
//            if (attendNoteInfo == null) {
//                throw new ForestBaseException(
//                        LanguageUtils.codeMessage(ResultCode.OPERATE_ERROR.getCode(),
//                                saveNoteRequest.getAttendInfoId()));
//            }
//            attendNoteInfo.setTimeAt(DateUtils.parse(emergencyAffairs.getTimeAt(), DateUtils.yyyy_MM_dd_HH_mm_ss));
//            attendNoteInfo.setEventType(emergencyAffairs.getEventType());
//            attendNoteInfo.setTitle(emergencyAffairs.getTitle());
//            attendNoteInfo.setPlace(emergencyAffairs.getPlace());
//            attendNoteInfo.setLongitude(emergencyAffairs.getLongitude());
//            attendNoteInfo.setLatitude(emergencyAffairs.getLatitude());
//            attendNoteInfo.setSiteSituation(emergencyAffairs.getSiteSituation());
//            attendNoteInfo.setCurrentSituation(emergencyAffairs.getCurrentSituation());
//            attendNoteInfo.setDisposal(emergencyAffairs.getDisposal());
//            attendNoteInfo.setDescription(emergencyAffairs.getDescription());
//            attendNoteInfo.setUpdatedAt(now);
//            attendNoteInfoDAO.updateById(attendNoteInfo);
//
//            //领导指示
//            List<String> descriptionList = emergencyAffairs.getDescriptionList();
//            if (CollectionUtil.isNotEmpty(descriptionList)) {
//                List<AttendNoteInfo> attendNoteInfos = new ArrayList<>();
//                descriptionList.forEach(s -> {
//                    attendNoteInfos.add(AttendNoteInfo.builder()
//                            .userId(microSysUserAllInfoVo.getId())
//                            .districtCode(districtCode)
//                            .districtName(attendInfo.getDistrictName())
//                            .userName(microSysUserAllInfoVo.getUserName())
//                            .mobile(microSysUserAllInfoVo.getMobile())
//                            .deptId(microSysUserAllInfoVo.getDeptId())
//                            .deptName(microSysUserAllInfoVo.getDeptName())
//                            .duty(microSysUserAllInfoVo.getDuty())
//                            .createdAt(now)
//                            .createdBy(userId)
//                            .updatedAt(now)
//                            .updatedBy(userId)
//                            .deleted(false)
//                            .attendId(saveNoteRequest.getAttendInfoId())
//                            .submitAt(now)
//                            .type(5)
//                            .parentId(attendNoteInfo.getId())
//                            .description(s)
//                            .build());
//                });
//                attendNoteInfoDAO.insertBatchSomeColumn(attendNoteInfos);
//            }
//        }
//    }
//
//    /**
//     * 保存晨报
//     *
//     * @param saveNoteRequest saveNoteRequest
//     */
//    public void saveDaily(SaveNoteRequest saveNoteRequest) {
//        Long userId = saveNoteRequest.getUserId();
//        String districtCode = saveNoteRequest.getDistrictCode();
//
//        com.telit.common.core.utils.Result<Map<Long, MicroSysUserAllInfoVo>> selectUserContainDeptAndRoleWithBatchIdsResult = remoteUpmsService.selectUserContainDeptAndRoleWithBatchIds(
//                Arrays.asList(userId), true);
//        Map<Long, MicroSysUserAllInfoVo> longMicroSysUserAllInfoVoMap = FeignUtils.unwrap(
//                selectUserContainDeptAndRoleWithBatchIdsResult);
//        MicroSysUserAllInfoVo microSysUserAllInfoVo = longMicroSysUserAllInfoVoMap.get(userId);
//        if (microSysUserAllInfoVo == null) {
//            throw new ForestBaseException(LanguageUtils.codeMessage(ResultCode.OPERATE_ERROR.getCode(), userId));
//        }
//
//        LambdaQueryWrapper<AttendInfo> attendInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::isDeleted, false);
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::getId, saveNoteRequest.getAttendInfoId());
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::getUserId, userId);
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::getDistrictCode, districtCode);
//        AttendInfo attendInfo = attendInfoDAO.selectOne(attendInfoLambdaQueryWrapper);
//        if (attendInfo == null) {
//            throw new ForestBaseException(
//                    LanguageUtils.codeMessage(ResultCode.OPERATE_ERROR.getCode(), saveNoteRequest.getAttendInfoId()));
//        }
//
//        SaveNoteRequest.Daily daily = saveNoteRequest.getDaily();
//        Date now = new Date();
//        Long id = daily.getId();
//        if (id == null) {
//            AttendNoteInfo attendNoteInfo = AttendNoteInfo.builder()
//                    .userId(microSysUserAllInfoVo.getId())
//                    .districtCode(districtCode)
//                    .districtName(attendInfo.getDistrictName())
//                    .userName(microSysUserAllInfoVo.getUserName())
//                    .mobile(microSysUserAllInfoVo.getMobile())
//                    .deptId(microSysUserAllInfoVo.getDeptId())
//                    .deptName(microSysUserAllInfoVo.getDeptName())
//                    .duty(microSysUserAllInfoVo.getDuty())
//                    .createdAt(now)
//                    .createdBy(userId)
//                    .updatedAt(now)
//                    .updatedBy(userId)
//                    .deleted(false)
//                    .attendId(saveNoteRequest.getAttendInfoId())
//                    .submitAt(now)
//                    .type(1)
//                    .workInfo(daily.getWorkInfo())
//                    .dispatchInfo(daily.getDispatchInfo())
//                    .fireFeedback(daily.getFireFeedback())
//                    .analyseInfo(daily.getAnalyseInfo())
//                    .build();
//            attendNoteInfoDAO.insert(attendNoteInfo);
//        } else {
//            LambdaQueryWrapper<AttendNoteInfo> attendNoteInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
//            attendNoteInfoLambdaQueryWrapper.eq(AttendNoteInfo::isDeleted, false);
//            attendNoteInfoLambdaQueryWrapper.eq(AttendNoteInfo::getId, id);
//            AttendNoteInfo attendNoteInfo = attendNoteInfoDAO.selectOne(attendNoteInfoLambdaQueryWrapper);
//            if (attendNoteInfo == null) {
//                throw new ForestBaseException(
//                        LanguageUtils.codeMessage(ResultCode.OPERATE_ERROR.getCode(),
//                                saveNoteRequest.getAttendInfoId()));
//            }
//            attendNoteInfo.setWorkInfo(daily.getWorkInfo());
//            attendNoteInfo.setDispatchInfo(daily.getDispatchInfo());
//            attendNoteInfo.setFireFeedback(daily.getFireFeedback());
//            attendNoteInfo.setAnalyseInfo(daily.getAnalyseInfo());
//            attendNoteInfo.setUpdatedAt(now);
//            attendNoteInfoDAO.updateById(attendNoteInfo);
//        }
//    }
//
//    /**
//     * 保存值班信息
//     *
//     * @param saveNoteRequest saveNoteRequest
//     */
//    public void saveDuty(SaveNoteRequest saveNoteRequest) {
//        Long userId = saveNoteRequest.getUserId();
//        String districtCode = saveNoteRequest.getDistrictCode();
//
//        com.telit.common.core.utils.Result<Map<Long, MicroSysUserAllInfoVo>> selectUserContainDeptAndRoleWithBatchIdsResult = remoteUpmsService.selectUserContainDeptAndRoleWithBatchIds(
//                Arrays.asList(userId), true);
//        Map<Long, MicroSysUserAllInfoVo> longMicroSysUserAllInfoVoMap = FeignUtils.unwrap(
//                selectUserContainDeptAndRoleWithBatchIdsResult);
//        MicroSysUserAllInfoVo microSysUserAllInfoVo = longMicroSysUserAllInfoVoMap.get(userId);
//        if (microSysUserAllInfoVo == null) {
//            throw new ForestBaseException(LanguageUtils.codeMessage(ResultCode.OPERATE_ERROR.getCode(), userId));
//        }
//
//        LambdaQueryWrapper<AttendInfo> attendInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::isDeleted, false);
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::getId, saveNoteRequest.getAttendInfoId());
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::getUserId, userId);
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::getDistrictCode, districtCode);
//        AttendInfo attendInfo = attendInfoDAO.selectOne(attendInfoLambdaQueryWrapper);
//        if (attendInfo == null) {
//            throw new ForestBaseException(
//                    LanguageUtils.codeMessage(ResultCode.OPERATE_ERROR.getCode(), saveNoteRequest.getAttendInfoId()));
//        }
//
//        SaveNoteRequest.Duty duty = saveNoteRequest.getDuty();
//        Date now = new Date();
//        AttendNoteInfo attendNoteInfo = AttendNoteInfo.builder()
//                .userId(microSysUserAllInfoVo.getId())
//                .districtCode(districtCode)
//                .districtName(attendInfo.getDistrictName())
//                .userName(microSysUserAllInfoVo.getUserName())
//                .mobile(microSysUserAllInfoVo.getMobile())
//                .deptId(microSysUserAllInfoVo.getDeptId())
//                .deptName(microSysUserAllInfoVo.getDeptName())
//                .duty(microSysUserAllInfoVo.getDuty())
//                .createdAt(now)
//                .createdBy(userId)
//                .updatedAt(now)
//                .updatedBy(userId)
//                .deleted(false)
//                .attendId(saveNoteRequest.getAttendInfoId())
//                .submitAt(now)
//                .type(2)
//                .description(duty.getDescription())
//                .build();
//        attendNoteInfoDAO.insert(attendNoteInfo);
//    }
//
//    /**
//     * 保存交班信息
//     *
//     * @param saveNoteRequest saveNoteRequest
//     */
//    public void saveTurn(SaveNoteRequest saveNoteRequest) {
//        Long userId = saveNoteRequest.getUserId();
//        String districtCode = saveNoteRequest.getDistrictCode();
//
//        com.telit.common.core.utils.Result<Map<Long, MicroSysUserAllInfoVo>> selectUserContainDeptAndRoleWithBatchIdsResult = remoteUpmsService.selectUserContainDeptAndRoleWithBatchIds(
//                Arrays.asList(userId), true);
//        Map<Long, MicroSysUserAllInfoVo> longMicroSysUserAllInfoVoMap = FeignUtils.unwrap(
//                selectUserContainDeptAndRoleWithBatchIdsResult);
//        MicroSysUserAllInfoVo microSysUserAllInfoVo = longMicroSysUserAllInfoVoMap.get(userId);
//        if (microSysUserAllInfoVo == null) {
//            throw new ForestBaseException(LanguageUtils.codeMessage(ResultCode.OPERATE_ERROR.getCode(), userId));
//        }
//
//        LambdaQueryWrapper<AttendInfo> attendInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::isDeleted, false);
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::getId, saveNoteRequest.getAttendInfoId());
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::getUserId, userId);
//        attendInfoLambdaQueryWrapper.eq(AttendInfo::getDistrictCode, districtCode);
//        AttendInfo attendInfo = attendInfoDAO.selectOne(attendInfoLambdaQueryWrapper);
//        if (attendInfo == null) {
//            throw new ForestBaseException(
//                    LanguageUtils.codeMessage(ResultCode.OPERATE_ERROR.getCode(), saveNoteRequest.getAttendInfoId()));
//        }
//
//        //校验晨报、值班记录
//        List<DailyDTO> dailyDTOS = qryDaily(userId, districtCode, saveNoteRequest.getAttendInfoId());
//        if (CollectionUtil.isEmpty(dailyDTOS)) {
//            throw new ForestBaseException("晨报未完成，无法交班！");
//        }
//        List<DutyDTO> dutyDTOS = qryDuty(userId, districtCode, saveNoteRequest.getAttendInfoId());
//        if (CollectionUtil.isEmpty(dutyDTOS)) {
//            throw new ForestBaseException("值班记录未完成，无法交班！");
//        }
//
//        SaveNoteRequest.Turn turn = saveNoteRequest.getTurn();
//        Date now = new Date();
//        AttendNoteInfo attendNoteInfo = AttendNoteInfo.builder()
//                .userId(microSysUserAllInfoVo.getId())
//                .districtCode(districtCode)
//                .districtName(attendInfo.getDistrictName())
//                .userName(microSysUserAllInfoVo.getUserName())
//                .mobile(microSysUserAllInfoVo.getMobile())
//                .deptId(microSysUserAllInfoVo.getDeptId())
//                .deptName(microSysUserAllInfoVo.getDeptName())
//                .duty(microSysUserAllInfoVo.getDuty())
//                .createdAt(now)
//                .createdBy(userId)
//                .updatedAt(now)
//                .updatedBy(userId)
//                .deleted(false)
//                .attendId(saveNoteRequest.getAttendInfoId())
//                .submitAt(now)
//                .type(3)
//                .turnId(turn.getTurnId())
//                .turnName(turn.getTurnName())
//                .turnMobile(turn.getTurnMobile())
//                .description(turn.getDescription())
//                .build();
//        attendNoteInfoDAO.insert(attendNoteInfo);
//    }
//
//}
